#include "Helpers.h"
//#include "TestUtils.h"
#include <map>


//-----------------------------------------------------------------------------
// Public
//-----------------------------------------------------------------------------

//*****************************************************************************
// Debug Class Implementation
//*****************************************************************************

std::ostream Debug::m_outStream(std::cout.rdbuf());

//-----------------------------------------------------------------------------
//PrintDebugMsg - Prints a debug message to debug stream
//-----------------------------------------------------------------------------
/*static*/ void Debug::PrintDebugMsg(string msg)
{
	string currTime = GetCurrentTime(false);
	m_outStream << currTime << " :: " << msg << endl;
	m_outStream.flush();
}

//-----------------------------------------------------------------------------
//changeDebugStreamToFile - sets debug stream to an outputfile or stdout
// Parameters:
// isStdout - if true, directs to STDOUT
//-----------------------------------------------------------------------------
/*static*/ void Debug::changeDebugStream(bool isStdout)
{
	if(isStdout)
	{
		m_outStream.rdbuf(std::cout.rdbuf());
	}
	else
	{
		string fileName = GetCurrentTime(true);
		fileName += "_permutations.debug";
		std::ofstream *fileStream = new std::ofstream(fileName.c_str());
		m_outStream.rdbuf(fileStream->rdbuf());
	}
}

/*****************************************************************************/
// Logger
// Implementation of the Logger functions
/*****************************************************************************/
//----------------------------------------------------------------------------
// LogMessage - Print a log message
//----------------------------------------------------------------------------
void Logger::LogMessage(string msg)
{
	string time = GetCurrentTime(false);
	cout << time << " :: " << msg << endl;
	Debug::PrintDebugMsg(msg);
}

//-----------------------------------------------------------------------------
//GetCurrentTime - outputs current time for logs or log file names
//-----------------------------------------------------------------------------
string GetCurrentTime(bool isForFileName)
{
	time_t rawtime;
	struct tm * timeinfo = new struct tm;
	char buffer [80];
	time ( &rawtime );	
	localtime_s (timeinfo, &rawtime );
	if(isForFileName)
		strftime (buffer,80,"%d-%m_%H-%M",timeinfo);
	else
		strftime (buffer,80,"%d.%m %H:%M",timeinfo);
	string time = buffer;
	return time;		
}